home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / utility / blrmu13.zip / BIRDCALL.ASM < prev    next >
Assembly Source File  |  1990-05-28  |  7KB  |  208 lines

  1. page ,132
  2. title birdcall ( intro to parkers mood ) as of 05-28-90  04:45 pm
  3. ;
  4. ;   read through arrays of tones and durations using timer channel 2
  5. ;
  6. ;   from p. 109 - PC Resource May 1987 ( hardin brothers )
  7. ;   ( minor modifications by bud rasmussen )
  8. ;
  9. code     segment
  10. ;
  11.          assume cs:code,ds:code
  12. ;
  13.          org   256
  14. ;
  15. birdcall:
  16. ;
  17.          jmp   play
  18. ;
  19. ppipb    equ   61h                     ; PPI port b
  20. tccr     equ   43h                     ; timer chip cmd reg
  21. tc2      equ   42h                     ; timer channel 2
  22. ;
  23. ;    The following is the note table -- the calculation formula is:
  24. ;    note value = int ((1193180 / frequency) +.5)
  25. ;
  26. notes:
  27.          dw    9122                    ; c    1   ( c below middle c )
  28.          dw    8609                    ; c#   2
  29.          dw    8128                    ; d    3
  30.          dw    7668                    ; d#   4
  31.          dw    7240                    ; e    5
  32.          dw    6834                    ; f    6
  33.          dw    6450                    ; f#   7
  34.          dw    6088                    ; g    8
  35.          dw    5745                    ; g#   9
  36.          dw    5424                    ; a    10
  37.          dw    5119                    ; a#   11
  38.          dw    4833                    ; b    12
  39. ;
  40.          dw    4559                    ; c    13  ( middle c )
  41.          dw    4304                    ; c#   14
  42.          dw    4063                    ; d    15
  43.          dw    3835                    ; d#   16
  44.          dw    3620                    ; e    17
  45.          dw    3417                    ; f    18
  46.          dw    3225                    ; f#   19
  47.          dw    3044                    ; g    20
  48.          dw    2873                    ; g#   21
  49.          dw    2712                    ; a    22
  50.          dw    2559                    ; a#   23
  51.          dw    2416                    ; b    24
  52. ;
  53.          dw    2280                    ; c    25  ( c above middle c )
  54.          dw    2152                    ; c#   26
  55.          dw    2031                    ; d    27
  56.          dw    1917                    ; d#   28
  57.          dw    1810                    ; e    29
  58.          dw    1708                    ; f    30
  59. ;
  60. ;    The following is the tune to be played.
  61. ;    The numbers are indexes into the list above.
  62. ;    The list is terminated with a -1.
  63. ;
  64. ;    to make a rest:
  65. ;    use note of 0 in tune table and length in time table.
  66. ;
  67. tune:
  68.          db    23
  69.          db    0
  70.          db    20
  71.          db    0
  72.          db    27
  73.          db    25
  74.          db    23
  75.          db    25
  76.          db    27
  77.          db    25
  78.          db    23
  79.          db    27
  80.          db    0
  81.          db    23
  82.          db    25
  83.          db    25
  84.          db    25
  85. ;
  86.          db    -1                      ; end of tune
  87. ;
  88. ;    Each entry in the following time table
  89. ;    corresponds to one of the notes above.
  90. ;    Times are multiples of the 18.2159 Hz heartbeat.
  91. ;
  92. time:
  93.          db    3
  94.          db    3
  95.          db    3
  96.          db    3
  97.          db    15
  98.          db    3
  99.          db    3
  100.          db    3
  101.          db    3
  102.          db    3
  103.          db    3
  104.          db    9
  105.          db    3
  106.          db    3
  107.          db    3
  108.          db    3
  109.          db    15
  110. ;
  111.          db    -1                      ; end of time table
  112. ;
  113. ;   start of program
  114. ;
  115. play:
  116.          mov   bx,1                    ; synchronize with the timer ticks
  117.          call  delay                   ; by waiting for next one
  118.          in    al,ppipb                ; get current port status
  119.          or    al,3                    ; turn on lo 2 bits
  120.          out   ppipb,al                ; open gate to timer
  121.          mov   bx,0                    ; note count
  122.          lea   di,time                 ; point to time table
  123. ;
  124. tuneloop:
  125.          lea   si,tune                 ; point to tune table
  126.          mov   al,[si][bx]             ; get tone
  127.          mov   dl,[di][bx]             ; get duration
  128.          mov   dh,0                    ; clear duration word
  129.          cmp   al,-1                   ; end ?
  130.          je    done                    ; if so, get out
  131.          push  bx                      ; save count
  132.          test  al,al                   ; rest ?
  133.          jne   norest                  ; if not, carry on
  134.          mov   bx,dx                   ; move duration
  135.          call  rest                    ; turn speaker off
  136.          jmp   repeat                  ; goto repeat
  137. ;
  138. norest:
  139.          cbw                           ; make tone a word
  140.          dec   ax                      ; offset ftom 0
  141.          shl   ax,1                    ; * 2 to index word table
  142.          mov   bx,ax                   ; move to bx
  143.          lea   si,notes                ; point to note table
  144.          mov   cx,[si][bx]             ; get the note
  145.          call  maketone                ; turn speaker on
  146.          mov   bx,dx                   ; move duration
  147.          call  delay                   ; wait while it plays
  148. ;
  149. repeat:
  150.          mov   bx,0                    ; break between notes
  151.          call  rest                    ; turn speaker off
  152.          pop   bx                      ; retrieve count
  153.          inc   bx                      ; + 1
  154.          jmp   tuneloop                ; do it again
  155. ;
  156. ;*-------------------------
  157. ;*  sub routines
  158. ;*-------------------------
  159. ;
  160. ;   Enter maketone with frequency in cx
  161. ;   This routine starts the speaker going
  162. ;   Uses: AX
  163. ;
  164. maketone:
  165.          mov   al,10110110b            ; set up timer for ch 2
  166.          out   tccr,al                 ; timer chip ready for count
  167.          mov   al,cl                   ; get lsb of note
  168.          out   tc2,al                  ; send to timer
  169.          mov   al,ch                   ; get msb of note
  170.          out   tc2,al                  ; now note has started
  171.          ret
  172. ;
  173. ;     Enter delay with delay count in bx
  174. ;     This routine will pause for bx / 18.2 seconds
  175. ;     Uses: AX, CX, DX
  176. ;
  177. delay:
  178.          mov   ah,0                    ; timer function - get time count
  179.          int   26                      ; timer count in cx:dx
  180.          add   bx,dx                   ; add to delay count
  181. delayl:
  182.          int   26                      ; get new timer count
  183.          cmp   bx,dx                   ; thru ?
  184.          jne   delayl                  ; if not, carry on
  185.          ret
  186. ;
  187. ;     Enter rest routine with count in BX
  188. ;
  189. rest:
  190.          in    al,ppipb                ; get current port status
  191.          push  ax                      ; save status
  192.          and   al,11111100b            ; turn off 2 lo bits
  193.          out   ppipb,al                ; send out
  194.          call  delay                   ; now wait
  195.          pop   ax                      ; get back value
  196.          out   ppipb,al                ; turn speaker on
  197.          ret
  198. ;
  199. done:
  200.          in    al,ppipb                ; get port status
  201.          and   al,11111100b            ; turn off 2 lo bits
  202.          out   ppipb,al                ; send it out
  203.          int   32                      ; get out
  204. ;
  205. code     ends
  206. ;
  207.          end   birdcall
  208.